#include "conv.h"
using namespace cv;
using namespace std;
int main(){
    // cv::Mat img = cv::imread("/home/lin/桌面/openvino/test.png",0);
    // cout<<"img:"<<img.cols<<","<<img.rows<<endl;
    unsigned char points[] = {
        1,2,3,4,5,
        6,7,8,9,10,
        11,12,13,14,15,
        16,17,18,19,20,
        21,22,23,24,25
    };
    cv::Mat img(5,5,CV_8UC1,points);
    float kernel_elements[] = {
        1.0f/12,2.0f/12,1.0f/12,
        2.0f/12,0.f,2.0f/12,
        1.0f/12,2.0f/12,1.0f/12
    };
    cv::Mat kernel(3,3,CV_32F,kernel_elements);
    cv::Mat my_output,output;

    cv::filter2D(img,output,CV_32F,kernel,cv::Point(-1,-1),0,cv::BORDER_CONSTANT);
    // int padding[]={0,0,0,0};
    my_output = conv2d(img,kernel);

    cout<<output<<endl;
    cout<<"------------"<<endl;
    cout<<my_output<<endl;

    cv::Mat normal_output,normal_my_output;
    cv::normalize(output,normal_output,0,1,cv::NORM_MINMAX);
    cv::normalize(my_output,normal_my_output,0,1,NORM_MINMAX);
    cout<<"cv filter:"<<output.cols<<","<<output.rows<<endl;
    cout<<"my conv output"<<normal_my_output.cols<<","<<normal_my_output.rows<<endl;
    cv::Mat diff = (normal_output != normal_my_output);
    bool eq = cv::countNonZero(diff)==0;
    cout<<eq<<endl;
    imshow("my conv",normal_my_output);
    imshow("cv filter2d",normal_output);
    imshow("diff",diff);
    cv::waitKey(0);
    return 0;
}